<template>
    <div>
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>修改用户密码</span>
                <!--                <el-button style="float: right; padding: 3px 0" type="text">添加</el-button>-->
            </div>
            <div class="text item">
                <el-form :label-position="labelPosition" ref="ruleForm" label-width="80px"
                         :model="formLabelAlign" >

                    <el-form-item label="用户名" prop="uname" >
                        <el-input  v-model="formLabelAlign.uname" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="密码" prop="upass">
                        <el-input v-model="formLabelAlign.upass"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click.native.prevent="changepass" >修改密码</el-button>
                        <el-button @click="resetForm">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
    </div>
</template>

<script>
    import {ChangePass} from "../../network/user";
    import {getTokenUser} from "../../utils/auth";

    export default {
        name: "ChangeUserPass",
        data(){
            return{
                labelPosition: 'right',
                formLabelAlign: {
                    uname: getTokenUser(),
                    upass: '',
                },

            }
        },
        methods:{
            resetForm() {
                this.$refs.ruleForm.resetFields();
            },
            changepass(){
                ChangePass(this.formLabelAlign).then(res => {
                    console.log(res)
                    if (res === 1) {
                        this.$message({
                            message: '修改成功',
                            type: 'success'
                        });
                    }else if (res === -1){
                        this.$message.error('用户不存在');
                    }else {
                        this.$message.error('失败');
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .text {
        font-size: 14px;
    }

    .item {
        margin-bottom: 18px;
        width: 30vw;
    }

    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
        clear: both
    }

    .box-card {
        width: 100%;
        height: 85vh;
    }
</style>
